﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;

namespace AvaVSExt.Helpers
{
    public static class CsprojHelper
    {
        public static string GetRootNamespace(string csprojPath)
        {
            const string OpenRootNamespace = "<RootNamespace>";
            const string CloseRootNamespace = "</RootNamespace>";

            var text = File.ReadAllText(csprojPath);

            var startIndex = text.IndexOf(OpenRootNamespace);
            if (startIndex == -1) return string.Empty;

            var endIndex = text.IndexOf(CloseRootNamespace);

            if (endIndex == -1) return string.Empty;

            var innerValue = text.Substring(startIndex + OpenRootNamespace.Length, endIndex - startIndex - OpenRootNamespace.Length);

            return innerValue.Trim();
        }
    }
}
